One of the hallmarks of modern user interfaces are modeless dialog boxes and data entry forms. They feature text entry fields, push buttons, check boxes, and a variety of other so-called controls. Oberon addresses these issues in a unique way:
- new controls can be implemented in Oberon itself; they are just specialized views
- every view which may contain other views (container view) can thus contain controls, and
each container view can act as input mask when desired
- controls can be directly linked to variables of a program
- linking is done automatically, taking into account type information about the variables to
guarantee consistency
- initial form layouts can be generated automatically out of a record declaration
- forms can be edited interactively and stored as documents, no intermediate code generation
is necessary
- yet form layouts may be created or manipulated by an Oberon program, if this is desired.
Some of these aspects can be demonstrated with the example below:
Compile this module and then execute New
Form... in the Dev menu. A dialog will be opened. Now type SamplesEx2.adr into its link field, and then click on the Create button. A new window with the following contents will be opened:
This form layout can be edited, e.g. by moving the Text button somewhat to the right. (Note that you have modified the document by doing that, thus you will be asked whether to save it when you try to close it. Answer by clicking on the Don't
Save button.)
Now execute the Open
Dialog
(Aux) command in the Dev menu. As a result, you get a fully functional dialog with the current layout. This mask can be used right away, i.e. when you click into the update check box, the variable SamplesEx2.adr.update will be toggled!
Note that if you click on the Text button, an error message will be displayed; because the corresponding procedure variable has not yet been set up.
If you have several views on the same variable (e.g. both the layout and the mask window), they will reflect all changes to the input you make.
A form's controls are linked to a program variable in a similar way as a text view is linked to its text. Both text views and controls are extensions of the type Views.View. The container of the above controls is a form view, also an extension of Views.View. Form views, just as text views, are examples of container views: container views may contain some intrinsic contents (e.g. text pieces) as well as arbitrary other views.
Instead of starting with a record declaration as in the above example, you may prefer to start with the interactive design of a dialog, and only later turn to the programming aspects. This is perfectly possible as well; just leave the link field in the New
Form dialog empty before clicking Create. An empty form window will be opened, and the Layout and Controls menus will appear. Using the commands in the Controls menu, new controls can be inserted into the form. The form can be saved in a file, and its controls may later be connected to program variables using a tool called the inspector. See the User's Guide for details on how to use it.
In this example we have seen how a form is used, from the perspective of a programmer as well as from the perspective of a user interface designer. Furthermore we have seen how an initial form layout can be generated automatically, how a form can be viewed (even simultaneously) both as a layout and as a dialog, and how a control, like any other view, may live in an arbitrary container view, not just in a form view.